package com.ruoyi.inventory.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.inventory.domain.InventoryManagement;
import com.ruoyi.inventory.service.IInventoryManagementService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 存货管理Controller
 * 
 * @author ruoyi
 * @date 2025-03-13
 */
@RestController
@RequestMapping("/management")
public class InventoryManagementController extends BaseController
{
    @Autowired
    private IInventoryManagementService inventoryManagementService;


    /**
     * 查询所有下拉框数据
     * @return
     */
    @GetMapping("getSelectAllData")
    public AjaxResult getSelectAll()
    {
        return success(inventoryManagementService.getSelectAllData());
    }



    /**
     * 查询存货管理列表
     */
    @RequiresPermissions("inventory:management:list")
    @GetMapping("/list")
    public TableDataInfo list(InventoryManagement inventoryManagement)
    {
        startPage();
        List<InventoryManagement> list = inventoryManagementService.selectInventoryManagementList(inventoryManagement);
        return getDataTable(list);
    }

    /**
     * 导出存货管理列表
     */
    @RequiresPermissions("inventory:management:export")
    @PostMapping("/export")
    public void export(HttpServletResponse response, InventoryManagement inventoryManagement)
    {
        List<InventoryManagement> list = inventoryManagementService.selectInventoryManagementList(inventoryManagement);
        ExcelUtil<InventoryManagement> util = new ExcelUtil<InventoryManagement>(InventoryManagement.class);
        util.exportExcel(response, list, "存货管理数据");
    }

    /**
     * 获取存货管理详细信息
     */
    @RequiresPermissions("inventory:management:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(inventoryManagementService.selectInventoryManagementById(id));
    }

    /**
     * 新增存货管理
     */
    @RequiresPermissions("inventory:management:add")
    @PostMapping
    public AjaxResult add(@RequestBody InventoryManagement inventoryManagement)
    {
        return toAjax(inventoryManagementService.insertInventoryManagement(inventoryManagement));
    }

    /**
     * 修改存货管理
     */
    @RequiresPermissions("inventory:management:edit")
    @PutMapping
    public AjaxResult edit(@RequestBody InventoryManagement inventoryManagement)
    {
        return toAjax(inventoryManagementService.updateInventoryManagement(inventoryManagement));
    }

    /**
     * 删除存货管理
     */
    @RequiresPermissions("inventory:management:remove")
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(inventoryManagementService.deleteInventoryManagementByIds(ids));
    }
}
